package mobile.android.portal.ui;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.w3c.dom.Text;

import mobile.android.portal.R;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.opengl.Visibility;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class PlaceOrderActivity extends Activity{

	String productName;
	String categoyName;
	
	Date dateDay, dateMonth, dateYear;
	
	TextView productNameTextView;
	TextView categoryNameTextView;
	TextView dateTextView;
	EditText quantity, tp;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_place_order);
        
        dateDay = new Date();
        dateMonth = new Date();
        dateYear = new Date();
        
        productName = getIntent().getExtras().getString("product_name");
        categoyName = getIntent().getExtras().getString("category_name");
        
        dateTextView = (TextView) findViewById(R.id.dateTextView);         
        productNameTextView = (TextView) findViewById(R.id.productTextView);
        categoryNameTextView = (TextView) findViewById(R.id.categoryTextView);
        quantity = (EditText) findViewById(R.id.editText1);
        tp = (EditText) findViewById(R.id.editText3);
        
        
        productNameTextView.setText(productName);
        categoryNameTextView.setText(categoyName);
        //dateTextView.setText(Integer.toString(dateDay.getDate())+ "/"+Integer.toString(dateMonth.getDate())+"/"+Integer.toString(dateYear.getDate()));
        dateTextView.setText(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(dateDay));
        productNameTextView.setVisibility(View.VISIBLE);
        categoryNameTextView.setVisibility(View.VISIBLE);
        dateTextView.setVisibility(View.VISIBLE);
        
        
    }
	
	public void onSubmitButtonClick(View v) {
		
		String message = "Product Name : "+productName +"\n"+"Category Name : "+categoyName+"\nDate : "+Integer.toString(dateDay.getDate())+ "/"+Integer.toString(dateMonth.getDate())+"/"+Integer.toString(dateYear.getDate())+"\nQuantity : "+ quantity.toString();
		
    	Intent mainScreen = new Intent(this, MobileBusinessPortalActivity.class);
    	this.sendSMS("0714972675", message);
    	startActivity(mainScreen);
	}
	
	private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, MobileBusinessPortalActivity.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    } 
}
